﻿/*
	Copyright (c) 2013 Andrew Meyer

	Permission is hereby granted, free of charge, to any person obtaining a copy of this software
	and associated documentation files (the "Software"), to deal in the Software without
	restriction, including without limitation the right to use, copy, modify, merge, publish,
	distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all copies or
	substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
	BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
	DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System;

namespace Ascend
{
	/// <summary>
	/// A set of values that describes the scale of an object in three dimensions.
	/// </summary>
	public struct Scale3D : IEquatable<Scale3D>
	{
		#region Lifecycle
		/// <summary>
		/// Initializes a new instance of Ascend.Scale3D structure with given scale values.
		/// </summary>
		/// <param name="x">
		/// The X-axis scale value.
		/// </param>
		/// <param name="y">
		/// The Y-axis scale value.
		/// </param>
		/// <param name="z">
		/// The Z-axis scale value.
		/// </param>
		public Scale3D(double x, double y, double z)
		{
			_x = x;
			_y = y;
			_z = z;
		}

		/// <summary>
		/// Initializes a new instance of Ascend.Scale3D structure with given uniform scale value.
		/// </summary>
		/// <param name="scale">
		/// The scale value to use for all axes.
		/// </param>
		public Scale3D(double scale)
		{
			_x = scale;
			_y = scale;
			_z = scale;
		}
		#endregion

		#region Public Properties
		private double _x;
		/// <summary>
		/// Gets this Ascend.Scale3D's X-axis scale value.
		/// </summary>
		public double X
		{
			get
			{
				return _x;
			}
		}

		private double _y;
		/// <summary>
		/// Gets this Ascend.Scale3D's Y-axis scale value.
		/// </summary>
		public double Y
		{
			get
			{
				return _y;
			}
		}

		private double _z;
		/// <summary>
		/// Gets this Ascend.Scale3D's Z-axis scale value.
		/// </summary>
		public double Z
		{
			get
			{
				return _z;
			}
		}
		#endregion

		#region Operators
		/// <summary>
		/// Compares two Ascend.Scale3D structures for equality.
		/// </summary>
		/// <param name="value1">
		/// The first value to compare.
		/// </param>
		/// <param name="value2">
		/// The second value to compare.
		/// </param>
		/// <returns>
		/// Returns true if the X, Y, and Z scale values of <paramref name="value1"/> are equal to
		/// those of <paramref name="value2"/>. Returns false otherwise.
		/// </returns>
		/// <remarks>
		/// Because double values can lose precision when arithmetic operations are performed on
		/// them, a comparison between two Ascend.Scale3D instances that are logically equal might
		/// fail.
		/// </remarks>
		public static bool operator ==(Scale3D value1, Scale3D value2)
		{
			return value1.Equals(value2);
		}

		/// <summary>
		/// Compares two Ascend.Scale3D structures for inequality.
		/// </summary>
		/// <param name="value1">
		/// The first value to compare.
		/// </param>
		/// <param name="value2">
		/// The second value to compare.
		/// </param>
		/// <returns>
		/// Returns true if the X, Y, and Z scale values of <paramref name="value1"/> are different
		/// from those of <paramref name="value2"/>. Returns false otherwise.
		/// </returns>
		/// <remarks>
		/// Because double values can lose precision when arithmetic operations are performed on
		/// them, a comparison between two Ascend.Scale3D instances that are logically equal might
		/// fail.
		/// </remarks>
		public static bool operator !=(Scale3D value1, Scale3D value2)
		{
			return !value1.Equals(value2);
		}

		/// <summary>
		/// Multiplies the two Ascend.Scale3D structures and returns the result as an Ascend.Scale3D
		/// structure.
		/// </summary>
		/// <param name="value1">
		/// The first value to multiply.
		/// </param>
		/// <param name="value2">
		/// The second value to multiply.
		/// </param>
		/// <returns>
		/// Returns the element-wise product of the two Ascend.Scale3D structures.
		/// </returns>
		public static Scale3D operator *(Scale3D value1, Scale3D value2)
		{
			return new Scale3D(value1.X * value2.X, value1.Y * value2.Y, value1.Z * value2.Z);
		}

		/// <summary>
		/// Multiplies an Ascend.Scale3D structure by a scalar value and returns the result as an
		/// Ascend.Scale3D structure.
		/// </summary>
		/// <param name="scale">
		/// The Ascend.Scale3D structure to multiply.
		/// </param>
		/// <param name="scalar">
		/// The scalar value to multiply.
		/// </param>
		/// <returns>
		/// Returns the product of the Ascend.Scale3D structure and the scalar value.
		/// </returns>
		public static Scale3D operator *(Scale3D scale, double scalar)
		{
			return new Scale3D(scale.X * scalar, scale.Y * scalar, scale.Z * scalar);
		}

		/// <summary>
		/// Multiplies a scalar value by an Ascend.Scale3D structure and returns the result as an
		/// Ascend.Scale3D structure.
		/// </summary>
		/// <param name="scalar">
		/// The scalar value to multiply.
		/// </param>
		/// <param name="scale">
		/// The Ascend.Scale3D structure to multiply.
		/// </param>
		/// <returns>
		/// Returns the product of the scalar value and the Ascend.Scale3D structure.
		/// </returns>
		public static Scale3D operator *(double scalar, Scale3D scale)
		{
			return new Scale3D(scale.X * scalar, scale.Y * scalar, scale.Z * scalar);
		}

		/// <summary>
		/// Divides the two Ascend.Scale3D structures and returns the result as an Ascend.Scale3D
		/// structure.
		/// </summary>
		/// <param name="value1">
		/// The dividend.
		/// </param>
		/// <param name="value2">
		/// The divisor.
		/// </param>
		/// <returns>
		/// Returns the element-wise quotient of the two Ascend.Scale3D structures.
		/// </returns>
		public static Scale3D operator /(Scale3D value1, Scale3D value2)
		{
			return new Scale3D(value1.X / value2.X, value1.Y / value2.Y, value1.Z / value2.Z);
		}

		/// <summary>
		/// Divides an Ascend.Scale3D structure by a scalar value and returns the result as an
		/// Ascend.Scale3D structure.
		/// </summary>
		/// <param name="scale">
		/// The dividend.
		/// </param>
		/// <param name="scalar">
		/// The divisor.
		/// </param>
		/// <returns>
		/// Returns the quotient of the Ascend.Scale3D structure and the scalar value.
		/// </returns>
		public static Scale3D operator /(Scale3D scale, double scalar)
		{
			return new Scale3D(scale.X / scalar, scale.Y / scalar, scale.Z / scalar);
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Compares two Ascend.Scale3D structures for equality.
		/// </summary>
		/// <param name="value">
		/// The Ascend.Scale3D instance to compare to this instance.
		/// </param>
		/// <returns>
		/// Returns true if the instances are equal. Returns false otherwise.
		/// </returns>
		/// <remarks>
		/// Because double values can lose precision when arithmetic operations are performed on
		/// them, a comparison between two Ascend.Scale3D instances that are logically equal might
		/// fail.
		/// </remarks>
		public bool Equals(Scale3D value)
		{
			return X == value.X && Y == value.Y && Z == value.Z;
		}

		/// <summary>
		/// Determines whether the specified object is an Ascend.Scale3D structure and if so,
		/// whether the X, Y, and Z scale values of the specified object are equal to those of this
		/// Ascend.Scale3D instance.
		/// </summary>
		/// <param name="obj">
		/// The object to compare.
		/// </param>
		/// <returns>
		/// Returns true if the specified object is an Ascend.Scale3D structure and is identical to
		/// this instance. Returns false otherwise.
		/// </returns>
		/// <remarks>
		/// Because double values can lose precision when arithmetic operations are performed on
		/// them, a comparison between two Ascend.Scale3D instances that are logically equal might
		/// fail.
		/// </remarks>
		public override bool Equals(object obj)
		{
			if (obj == null || GetType() != obj.GetType())
			{
				return false;
			}

			return Equals((Scale3D)obj);
		}

		/// <summary>
		/// Returns a hash code for this Ascend.Scale3D structure.
		/// </summary>
		/// <returns>
		/// Returns a hash code for this Ascend.Scale3D structure.
		/// </returns>
		public override int GetHashCode()
		{
			return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
		}

		/// <summary>
		/// Creates a string representation of this Ascend.Scale3D structure.
		/// </summary>
		/// <returns>
		/// Returns a string containing the X, Y, and Z scale values of this Ascend.Scale3D
		/// structure.
		/// </returns>
		public override string ToString()
		{
			return X + ", " + Y + ", " + Z;
		}
		#endregion

		#region Static Methods
		/// <summary>
		/// Compares two Ascend.Scale3D structures for equality.
		/// </summary>
		/// <param name="value1">
		/// The first value to compare.
		/// </param>
		/// <param name="value2">
		/// The second value to compare.
		/// </param>
		/// <returns>
		/// Returns true if the X, Y, and Z scale values of <paramref name="value1"/> are equal to
		/// those of <paramref name="value2"/>. Returns false otherwise.
		/// </returns>
		/// <remarks>
		/// Because double values can lose precision when arithmetic operations are performed on
		/// them, a comparison between two Ascend.Scale3D instances that are logically equal might
		/// fail.
		/// </remarks>
		public static bool Equals(Scale3D value1, Scale3D value2)
		{
			return value1.Equals(value2);
		}
		#endregion
	}
}
